package com.talkyun.openx.server.helper;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class IconHelper {
    private static byte[] buffer;

    // "/webapp/favicon.ico"
    public static byte[] getFavIconBuffer(String path) {
        if (buffer == null) {
            try {
                InputStream ins = IconHelper.class.getResourceAsStream(path);
                byte[] buf = new byte[1024];
                ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
                int num = ins.read(buf);
                while (num != -1) {
                    baos.write(buf, 0, num);
                    num = ins.read(buf);
                }
                buffer = baos.toByteArray();
            } catch (IOException e) {
                buffer = new byte[0];
            }
        }
        return buffer;
    }
}